package com.kj.misc.service;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.kj.misc.domain.MiscConfig;

@Component
public class MiscBoss {
	
	@Autowired
	private MiscFetcherManager fetchers;
	
	@Autowired
	private MiscData data;
	
	@Autowired
	private MiscStorage storage;
	
	@Autowired
	private MiscDataFusion fusion;
	
	@Autowired
	private MiscDataFesh fesh;
	
	@Autowired
	private MiscDataFpa fpa;
	
	
	@PostConstruct
	public void initialize() {
				
		//
		start();
			
	}
	
	@PreDestroy
	public void terminate() {
		stop();
	}
	
	public void start() {
		
		// 载入配置文件
		MiscConfig.instance.reload();
		
		data.start();
		
		fetchers.start();
		
		fesh.initialize();
				
		fusion.initialize();
		
		fpa.initialize();
		
		storage.start();
		
	}
	
	public void stop() {
		
		fpa.terminate();
		
		fusion.terminate();
		
		fesh.terminate();
				
		fetchers.stop();
		
		storage.stop();
		
		data.stop();
		
	}
	
	public void reset() {
		
		stop();
		
		start();
		
	}

}
